#include "BoundingBox.h"
#include "Color.h"

BoundingBox::BoundingBox(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax)
	: _xmin(xmin), _ymin(ymin), _zmin(zmin), _xmax(xmax), _ymax(ymax), _zmax(zmax)
{
	CvarSystem& cvars = CvarSystem::getInstance();

	_draw = cvars.addCvar("m_bounding_box", false);
	_color = cvars.addCvar("m_bounding_box_color", WHITE);
}

void BoundingBox::render(RendererPtr renderer)
{
	if (!(_draw->getValueB())) {
		return;
	}

	int color = _color->getValueI();
	
	float wideth=_xmax-_xmin;
	float height=_ymax-_ymin;
	float depth=_zmax-_zmin;

	Vec3 bottomNearLeft(_xmin,_ymin,_zmin);
	Vec3 bottomNearRight(_xmax,_ymin,_zmin);
	Vec3 bottomFarLeft(_xmin,_ymin,_zmax);
	Vec3 bottomFarRight(_xmax,_ymin,_zmax);

	Vec3 upNearLeft(_xmin,_ymax,_zmin);
	Vec3 upNearRight(_xmax,_ymax,_zmin);
	Vec3 upFarLeft(_xmin,_ymax,_zmax);
	Vec3 upFarRight(_xmax,_ymax,_zmax);
	
	renderer->drawLine(bottomNearLeft, bottomNearRight, color);
	renderer->drawLine(bottomNearLeft, bottomFarLeft, color);
	renderer->drawLine(bottomFarLeft, bottomFarRight, color);
	renderer->drawLine(bottomFarRight, bottomNearRight, color);
	
	renderer->drawLine(upNearLeft, upNearRight, color);
	renderer->drawLine(upNearLeft, upFarLeft, color);
	renderer->drawLine(upFarLeft, upFarRight, color);
	renderer->drawLine(upFarRight, upNearRight, color);
	
	renderer->drawLine(bottomNearLeft, upNearLeft, color);
	renderer->drawLine(bottomNearRight, upNearRight, color);
	renderer->drawLine(bottomFarLeft, upFarLeft, color);
	renderer->drawLine(bottomFarRight, upFarRight, color);
}
